class Attribute < ApplicationRecord
  has_and_belongs_to_many :products, class_name: 'Product', join_table: 'products_attributes'

  validates :name, uniqueness: true

  after_update Proc.new{Product.reindex}

  def self.get_attr_id
    attr_hash = {}
    self.all.each{|val| attr_hash[val.name] = val.id}
    attr_hash
  end
end
